package com.xbongbong.saas.script.tempenum;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.enums.PhoneFormatSettingEnum;
import com.xbongbong.saas.enums.PhoneRepeatRuleEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.AllFieldEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/30 14:07
 * @since v1.0
 */
@Getter
public enum TempAllFieldEnum {
    // 模板设置界面展示字段
    NAME(AllFieldEnum.NAME),
    CUSTOMER_NAME(AllFieldEnum.CUSTOMER_NAME),
    PHONE(AllFieldEnum.PHONE),
    LEVEL(AllFieldEnum.LEVEL),
    IMPORTANT_DEGREE(AllFieldEnum.IMPORTANT_DEGREE),
    EMAIL(AllFieldEnum.EMAIL),
    ADDRESS(AllFieldEnum.ADDRESS),
    ZIP_CODE(AllFieldEnum.ZIP_CODE),
    BIRTHDAY(AllFieldEnum.BIRTHDAY),
    BIRTHDAY_LINK_TEXT(AllFieldEnum.BIRTHDAY_LINK_TEXT),
    LUNAR_BIRTHDAY_LINK_TEXT(AllFieldEnum.LUNAR_BIRTHDAY_LINK_TEXT),
    MEMO(AllFieldEnum.MEMO),
    CUSTOMER_NAME_LINK_TEXT(AllFieldEnum.CUSTOMER_NAME_LINK_TEXT),
    //  CREATOR_ID(AllFieldEnum.CREATOR_ID),
//    OUT_PRODUCTS(AllFieldEnum.OUT_PRODUCTS),
//    INTO_WAREHOUSE_ID(AllFieldEnum.INTO_WAREHOUSE_ID),
//    SIGN_TIME(AllFieldEnum.SIGN_TIME),
//    SIGN_PERSON(AllFieldEnum.SIGN_PERSON),
//    PAYMENT(AllFieldEnum.PAYMENT),
//    CONTRACT_NO(AllFieldEnum.CONTRACT_NO),
    VERSION(AllFieldEnum.VERSION),
    // VIDEO(AllFieldEnum.VIDEO),
//    LOCATION(AllFieldEnum.LOCATION),
//    IMAGES(AllFieldEnum.IMAGES),
//    MANAGER_ID(AllFieldEnum.MANAGER_ID),
//    CONTRACT_ID(AllFieldEnum.CONTRACT_ID),
//    ATTACHMENTS(AllFieldEnum.ATTACHMENTS),
    SPECIFICATION(AllFieldEnum.SPECIFICATION),
    STOCK(AllFieldEnum.STOCK),
    INSTRUCTION(AllFieldEnum.INSTRUCTION),
    //    APPROVED_PEOPLE(AllFieldEnum.APPROVED_PEOPLE),
    THIS_PLAN(AllFieldEnum.THIS_PLAN),
    EXECUTOR(AllFieldEnum.EXECUTOR),
    // CONTRACT_ID_LINK_TEXT(AllFieldEnum.CONTRACT_ID_LINK_TEXT),
    VERSION_LINK_TEXT(AllFieldEnum.VERSION_LINK_TEXT),
    COMMUNICATE_BUSINESS(AllFieldEnum.COMMUNICATE_BUSINESS),
    JXC_COMMUNICATE_BUSINESS(AllFieldEnum.JXC_COMMUNICATE_BUSINESS),
    COMMUNICATE_BUSINESS_TYPE(AllFieldEnum.COMMUNICATE_BUSINESS_TYPE),
    COMMUNICATE_BUSINESS_LINK_TEXT(AllFieldEnum.COMMUNICATE_BUSINESS_LINK_TEXT),
    NEXT_PLAN(AllFieldEnum.NEXT_PLAN),
    EXECUTOR_LINKED_TEXT(AllFieldEnum.EXECUTOR_LINKED_TEXT),
    ;

    private AllFieldEnum anEnum;

    TempAllFieldEnum(AllFieldEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempAllFieldEnum> getAllEnum() {
        List<TempAllFieldEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化关联客户
     *
     * @param fieldAttrEntity 字段解释实体
     */
    public static void initCustomerName(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        fieldAttrEntity.setLinkedText(CUSTOMER_NAME_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

//    /**
//     * 初始化关联合同
//     *
//     * @param fieldAttrEntity 字段解释实体
//     */
//    public static void initContractId(FieldAttrEntity fieldAttrEntity) {
//        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CONTRACT.getCode());
//        fieldAttrEntity.setLinkedText(CONTRACT_ID_LINK_TEXT.getAnEnum().getAttr());
//        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
//        saasParticularAttributePoJo.setMultiCheck(true);
//        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
//    }

    /**
     * 初始化联系电话
     *
     * @param fieldAttrEntity 字段解释实体
     */
    public static void initPhone(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField("text_1", "类型", "type", FieldTypeEnum.COMBO.getType(), 4, 1, 0, 1);
        String str = "工作,手机,住址,主要,传真,其他";
        item.setItems(InitExplainsHelper.setCombItem(str));
        items.add(item);
        FieldAttrEntity item2 = InitExplainsHelper.setField("text_2", "电话", "phone", FieldTypeEnum.TEXT.getType(), 4, 1, 0, 1);
        items.add(item2);
        subFormPoJo.setItems(items);
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setPhoneRepeatRule(PhoneRepeatRuleEnum.GLOBAL_OPEN.getCode());
        saasParticularAttributePoJo.setPhoneFormatSetting(PhoneFormatSettingEnum.ELEVEN_NUMBER.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setSubForm(subFormPoJo);
    }

    /**
     * 初始化联系人级别
     *
     * @param fieldAttrEntity 字段解释实体
     */
    public static void initLevel(FieldAttrEntity fieldAttrEntity) {
        String str = "基层,中层,高层";
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItem(str));
    }

    /**
     * 初始化回款
     *
     * @param fieldAttrEntity 字段解释实体
     */
    public static void initPayment(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField("text_1", "回款编号", "type", FieldTypeEnum.TEXT.getType(), 4, 1, 0, 1);
        items.add(item);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
    }

    /**
     * 初始化bom版本
     * 返回格式 {value: "m,,m", checked: 1}
     *
     * @param fieldAttrEntity 实体
     * @author feng.zheng
     * @date 2019/1/30 20:09
     */
    public static void initVersion(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        JSONObject textCheck = new JSONObject();
        textCheck.put("checkText", "设为默认版本");
        textCheck.put("isDefaultCheck", 0);
        saasParticularAttributePoJo.setTextCheck(textCheck);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 初始化客户跟进记录
     *
     * @param fieldAttrEntity 字段属性实体
     * @author feng.zheng
     * @date 2019/2/1 10:27
     */
    public static void initCommunicateBusiness(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(XbbRefTypeEnum.SALES_OPPORTUNITY.getName());
        Integer opportunityCode = XbbRefTypeEnum.SALES_OPPORTUNITY.getCode();
        itemPoJo.setValue(opportunityCode.toString());
        itemPoJo.setChecked(true);
        itemPoJos.add(itemPoJo);
        ItemPoJo itemPoJo1 = new ItemPoJo();
        itemPoJo1.setText(XbbRefTypeEnum.CONTRACT.getName());
        Integer contractCode = XbbRefTypeEnum.CONTRACT.getCode();
        itemPoJo1.setValue(contractCode.toString());
        itemPoJo1.setChecked(false);
        itemPoJos.add(itemPoJo1);
        fieldAttrEntity.setItems(itemPoJos);
    }

    /**
     * 初始化供应商跟进记录
     *
     * @param fieldAttrEntity 字段属性实体
     * @author feng.zheng
     * @date 2019/2/1 10:27
     */
    public static void initJxcCommunicateBusiness(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(XbbRefTypeEnum.PURCHASE.getName());
        Integer purchaseCode = XbbRefTypeEnum.PURCHASE.getCode();
        itemPoJo.setValue(purchaseCode.toString());
        itemPoJo.setChecked(true);
        itemPoJos.add(itemPoJo);
        fieldAttrEntity.setItems(itemPoJos);
    }

    public static void initThisPlan(FieldAttrEntity fieldAttrEntity) {
    }

    /**
     * 初始化明日计划子表单
     *
     * @param fieldAttrEntity 属性实体
     * @author feng.zheng
     * @date 2019/2/12 14:42
     */
    public static void initNextPlan(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField("text_1", "计划内容", "content", FieldTypeEnum.TEXT.getType(), 4, 1, 0, 1);
        items.add(item);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
    }

    public static void initExecutor(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo1 = new ItemPoJo();
        itemPoJo1.setText("负责人");
        itemPoJo1.setValue("0");
        itemPoJo1.setChecked(true);
        itemPoJos.add(itemPoJo1);
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText("协同人");
        itemPoJo2.setValue("1");
        itemPoJo2.setChecked(false);
        itemPoJos.add(itemPoJo2);
        ItemPoJo itemPoJo3 = new ItemPoJo();
        itemPoJo3.setText("自定义");
        itemPoJo3.setValue("2");
        itemPoJo3.setChecked(false);
        List<String> fieldMap = new ArrayList<>();
        fieldMap.add(EXECUTOR_LINKED_TEXT.anEnum.getAttr());
        itemPoJo3.setFieldMap(fieldMap);
        itemPoJos.add(itemPoJo3);
        fieldAttrEntity.setItems(itemPoJos);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("custom");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

}
